/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sunsite.action;

import com.opensymphony.xwork2.ActionSupport;
import java.util.List;
import java.util.Locale;
import org.springframework.context.support.ResourceBundleMessageSource;
import sunsite.po.Resume;
import sunsite.po.University;
import sunsite.po.Usr;
import sunsite.service.DatadicService;
import sunsite.service.ResumeService;
import sunsite.service.UniversityService;
import sunsite.service.UserService;
import sunsite.tools.ContextHelper;
import sunsite.tools.Naming;
import sunsite.vo.UserInfo;

/**
 *
 * @author mg
 */
public class FillinResume extends ActionSupport{
    private Resume resume;
    private String message;
    private List sexes;
    private List positions;
    private List degrees;
    private List gradeList;

    private String position;
    private String sex;
    private String identifier;
    private String mobile;
    private String selfDescription;


    private List<sunsite.po.University> universities;


    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
    
    private ResumeService resumeService;
    private UserService usrService;
    private DatadicService datadicService;
    private UniversityService uniService;

    private ResourceBundleMessageSource messageSource;

    public void setMessageSource(ResourceBundleMessageSource messageSource) {
        this.messageSource = messageSource;
    }
    public void setUsrService(UserService usrService) {
        this.usrService = usrService;
    }
    public void setDatadicService(DatadicService datadicService) {
        this.datadicService = datadicService;
    }

    public void setUniService(UniversityService uniService) {
        this.uniService = uniService;
    }


   @Override
    public String execute() throws Exception {
       sexes = datadicService.getDatadicValues("sex");
       positions = datadicService.getDatadicValues("position");
       degrees = datadicService.getDatadicValues("degree");
       gradeList = datadicService.getDatadicValues("grade");
       universities = uniService.getUniversityList();
       UserInfo user = (UserInfo)ContextHelper.getSession().get(Naming.SessionName.UserSession);
       if(user == null){
            message = messageSource.getMessage("message.notLogin", null, Locale.getDefault());
            return SUCCESS;
       }
       Usr usr = usrService.getUsrByName(user.getUserName());
       ContextHelper.getRequest().put("userUni", usr.getUniversity().getUniId());
       ContextHelper.getRequest().put("major", usr.getMajor());
       ContextHelper.getRequest().put("degree", usr.getDegree());
       ContextHelper.getRequest().put("grade", usr.getGrade());
       Resume r = (Resume)ContextHelper.getSession().get(Naming.SessionName.Resume);
       if(r == null){
           resume = new Resume();
           resume.setUsr(usr);
           ContextHelper.getSession().put(Naming.SessionName.Resume, resume);
       }else{
           resume = r;
           this.position = r.getPosition();
           this.sex = r.getSex();
           this.mobile = r.getMobile();
           this.identifier = r.getIdentifier();
           this.selfDescription = r.getSelfDescription();
       }
       return SUCCESS;
   }

    public void setResumeService(ResumeService resumeService) {
        this.resumeService = resumeService;
    }

    public Resume getResume() {
        return resume;
    }

    public void setResume(Resume resume) {
        this.resume = resume;
    }

    public List getSexes() {
        return sexes;
    }

    public void setSexes(List sex) {
        this.sexes = sex;
    }

    public List getPositions() {
        return positions;
    }

    public void setPositions(List position) {
        this.positions = position;
    }

    public List<University> getUniversities() {
        return universities;
    }

    public void setUniversities(List<University> universities) {
        this.universities = universities;
    }

    public List getDegrees() {
        return degrees;
    }

    public void setDegrees(List degrees) {
        this.degrees = degrees;
    }

    public List getGradeList() {
        return gradeList;
    }

    public void setGradeList(List gradeList) {
        this.gradeList = gradeList;
    }

    public String getIdentifier() {
        return identifier;
    }

    public void setIdentifier(String identifier) {
        this.identifier = identifier;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getPosition() {
        return position;
    }

    public void setPosition(String position) {
        this.position = position;
    }

    public String getSelfDescription() {
        return selfDescription;
    }

    public void setSelfDescription(String selfDescription) {
        this.selfDescription = selfDescription;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

}
